/**
 * 
 */
package com.homework.datastructures.exercise3.arrayQueue;

/**
 * @author public_enemy
 * 
 */
public class ArrayQueue<E> {

	private Object[] arrayQueue;
	private int maxCapacity;
	private int head;
	private int tail;
	private int numberOfElements;

	public ArrayQueue(int maxCapacity) {
		this.maxCapacity = maxCapacity;
		this.head = 0;
		this.tail = -1;
		this.numberOfElements = 0;
	}

	public int getSize() {
		return numberOfElements;
	}

	public void enqueue(E value) {
		if (tail == maxCapacity - 1) {
			tail = -1;
		}
		arrayQueue[++tail] = value;
		numberOfElements++;
	}

	public E dequeue() {
		E dequeueElement = (E) arrayQueue[head++];
		if (head == maxCapacity) {
			head = 0;
		}
		numberOfElements--;
		return dequeueElement;
	}

	public E getHead() {
		return (E) arrayQueue[head];
	}

	public boolean isEmpty() {
		return (numberOfElements == 0);
	}

	public boolean isFull() {
		return (numberOfElements == maxCapacity);
	}
}
